define(["esri/toolbars/navigation", "dojo/topic", "esri/geometry/Extent", "esri/SpatialReference"],
			function(Navigation, topic, Extent, SpatialReference) {
	var maps = {},
		navs = {},
		map=null,
		mainMapId = null,
		activatedMap = null,
		curCursor = "default",
		MapClick = null,
		MapDBClick=null,
		MapGraphicClick=null;
	return {
		/**
		 * @summary 将地图控件添加到当前对象中，以便管理、获取。
		 * @param map<map> 地图对象。
		 */
		addMap: function(map) {
			if(!map)
				throw new Error("参数map为空值");
			if(maps[map.id] == map) {
				console.log("map'" + map.id + "'已经添加到MapManager中");
				return;
			}
			maps[map.id] = map;
			if(!mainMapId) {
				//设置主地图
				mainMapId = map.id;
			}
			//当前激活的地图
			map.on("mouse-over", function(evt) {
				activatedMap = map;
			});
			//发布地图数据加载完成事件
			map.on('load', function(evt) {
				//map.disableDoubleClickZoom();
				//topic.publish("onemap/map/loaded",evt);
			});
			//发布地图创建事件
			//topic.publish("onemap/map/created",{map:map});
		},

		/**
		 * @summary 获得地图控件。
		 * @param mapId<string|esri.map> mapId 地图控件的标识，或者空值，返回主地图。
		 */
		getMap: function(mapId) {
			return mapId && mapId.declaredClass ? mapId : maps[mapId || mainMapId];
		},
		/**
		 * @summary 获得map的Navigation对象
		 * @param mapId<string|map>  地图的标识或者地图控件，此参数为空值时，返回主地图控件。
		 * @param create<boolean> 是否创建navigation对象。
		 * @return nav<esri.toolbars.navigation>
		 */
		getNav: function(mapId, create) {
			var map;
			if(mapId && typeof mapId == "object") {
				map = mapId;
				mapId = map.id;
			} else if(!mapId) {
				mapId = mainMapId;
			}
			if(!mapId) {
				console.log("MapManager#getNav:mapId为空值");
				return null;
			}
			var navId = mapId + "_nav",
				nav = navs[navId];
			if(!nav && create !== false) {
				if(!map) {
					map = this.getMap(mapId);
					if(!map) {
						console.log("MapManager#getNav:不存在标识为'" + mapId + "'的地图控件");
						return null;
					}
				}
				nav = new Navigation(map);
				navs[navId] = nav;
			}
			return nav;
		},
		/**
		 * @summary 设置地图鼠标样式 不传入时,获取上一次操作的值
		 * @param {Map} map
		 * @param {url|type} cursor
		 */
		setCursor: function(map, cursor) {
			if(cursor) {
				curCursor = map.cursor;
				map.setMapCursor(cursor);
			} else {
				map.setMapCursor(curCursor);
			}

		},
		/**
		 * @summary Full Extent
		 * @return <esri.geometry.Extent>
		 */
		getExtent: function() {
			return new Extent(167251.6336000003,4081403.5383,520751.6412000004,4383479.610300001, new SpatialReference(2382));
			//return new Extent(168080.44730000012,4081489.3347999994,520560.3448000001,4383277.2041, new SpatialReference(2382));
		},

		//给地图注册单击事件
		setMapClick:function(map,clickFunction){
			this.map = map;
			if(this.MapClick){
				this.MapClick.remove();
			}
			this.MapClick = map.on("click",clickFunction);
		},

		//给临时图层绑定单击事件
		setMapGraphicClick:function(map,afterClick){
			if(this.MapGraphicClick){
				this.MapGraphicClick.remove();
			}
			this.MapGraphicClick = map.graphics.on("click",afterClick);

		},
		removeClick:function(){
			if(this.MapClick){
				this.map.setMapCursor("default");
				this.MapClick.remove();
			}
		},

		removeMapGraphicClick:function(){
			if(this.MapGraphicClick){
				this.MapGraphicClick.remove();
			}

		},
		//给地图绑定双击事件
		setMapDBClick:function(map,clickFuntion){
			this.map = map;
			map.disableDoubleClickZoom();
			if(this.MapDBClick){
				this.MapDBClick.remove();
			}
			this.MapDBClick = map.on("dbl-click",clickFuntion);
		},
		//移除地图双击事件
		removeMapDBClick:function(){
			if(this.map ){
				this.map .enableDoubleClickZoom();
			}
			if(this.MapDBClick){
				this.MapDBClick.remove();
			}
		}

	};
});
